package by.demchenko.sample.webapp.page.home.share;

import by.demchenko.sample.datamodel.Course;
import by.demchenko.sample.datamodel.Section;
import by.demchenko.sample.services.CourseService;
import by.demchenko.sample.webapp.page.home.BaseLayout;
import by.demchenko.sample.webapp.page.home.panel.CoursePanel;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;

import javax.inject.Inject;
import java.util.List;

public class CourseDetailsPage extends BaseLayout {

    @Inject
    CourseService courseService;

    public CourseDetailsPage(Section section) {

        add(new Label("sectionName", section.getName(getSession().getLocale())));

        List<Course> courses = courseService.getCoursesBySection(section);

        add(new ListView<Course>("sectionsList", courses) {

            @Override
            protected void populateItem(ListItem<Course> item) {
                Course course = item.getModelObject();
                item.add((new CoursePanel("course", course)));
            }
        });

    }
}
